
require('../../lib/ui')

import { shopName } from '../../share/common';
import { Props as OpenIdPageProps, OpenIdPage } from './modules/openid'
import ReactDOM = require('react-dom');
import React = require('react');

function binding_action(element: HTMLElement) {
    let props: OpenIdPageProps = {
        title: '绑定微信',
        buttonText: '确定绑定',
        content: {
            normal: `确定要绑定微信号到${shopName}商家后台系统吗`,
            success: '已成功绑定微信号',
            fail: '绑定微信号失败，请重新扫描二维码'
        }
    }

    ReactDOM.render(<OpenIdPage {...props} />, element);
}

function adminLogin_action(element: HTMLElement) {
    let props: OpenIdPageProps = {
        title: '商家登录',
        buttonText: '确定登录',
        content: {
            normal: `确定要登录到${shopName}商家后台系统吗`,
            success: '已成功登录',
            fail: '登录号失败，请重新扫描二维码'
        }
    }

    ReactDOM.render(<OpenIdPage {...props} />, element);
}

function userLogin_action(element: HTMLElement) {
    let props: OpenIdPageProps = {
        title: '客户端登录',
        buttonText: '确定登录',
        content: {
            normal: `确定要登录到${shopName}客户端吗`,
            success: '已成功登录',
            fail: '登录号失败，请重新扫描二维码'
        }
    }

    ReactDOM.render(<OpenIdPage {...props} />, element);
}

function unbinding_action(element: HTMLElement) {
    let props: OpenIdPageProps = {
        // weixin: page.createService(WeiXinService),
        title: '解绑微信',
        buttonText: '确定解绑',
        content: {
            normal: '确定要解绑微信号吗',
            success: '已成功解绑微信号',
            fail: '解绑失败，请重新扫描二维码'
        }
    }

    ReactDOM.render(<OpenIdPage {...props} />, element);
}

let pageElement = document.createElement('div')
document.body.appendChild(pageElement)
switch (location.hash) {
    default:
    case '#index':
        break
    case '#binding':
        binding_action(pageElement)
        break
    case '#unbinding':
        unbinding_action(pageElement)
        break
    case '#adminLogin':
        adminLogin_action(pageElement)
        break
    case '#userLogin':
        userLogin_action(pageElement)
        break

}

// define('modules/index', function (mod) {
//     mod.default = (page: chitu.Page) => null
//     return mod
// })

// define('modules/binding', function (mod) {
//     mod.default = binding_action
//     return mod
// })

// define('modules/unbinding', function (mod) {
//     mod.default = unbinding_action
//     return mod
// })

// define('modules/adminLogin', function (mod) {
//     mod.default = adminLogin_action
//     return mod
// })

// define('modules/userLogin', function (mod) {
//     mod.default = userLogin_action
//     return mod
// })

// let app = new Application()
// app.run()